/*
 ============================================================================
 Name        : class1.c
 Author      : hwg
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */


#include "./header/common.h"
int main(int argc, char **argv) {
	if(argc < 2)
		{
				printf("%s<mode num><target file>\n",argv[0]);
				exit(0);
		}
		int i = 0;
		printf("\n*********inputstring detail start*************");
		char **argvf = argv;
		for(i = argc; i>0; i--)
		{
				printf("\nthe\t%d\tstring is\t%s\n",i,*argvf);
				argvf = argvf+1;
		}
		printf("\n********inputstring detail end****************\n");
/*文件*/
		int souce;
		int config;
		int lite;
		int gra;
		int gotos;
		printf("\n********************words init***********************\n");
		souce = openfile(argv[1]);
		if(my_read(souce, buffsource)> -1)
			printf("read success \n");
		else
			printf("bad\n");
		printf("\nthe words\n%s\n",buffsource);
		LinkList words;
		initlist_wordlist(&words ,buffsource);
		printf_wordlist(words);
		close(souce);
		printf("\n********************keylist init***********************\n");
		config = openfile("./config.txt");
		if(my_read(config, buffconfig)> -1)
			printf("read success \n");
		else
			printf("bad\n");
		printf("\nthe config\n%s\n",buffconfig);
		LinkList keyc;
		initlist_keylist(&keyc ,buffconfig);
		printf_keylist(keyc);
		ElemType b;
		Listgetnode(keyc,3,&b);
		printf("\nthe node.words =%s\tthe node.exp=%s\n",b.unikeynode.words,b.unikeynode.exp);
		match(words ,keyc);
		printf_wordlist(words);
		close(config);
		printf("\n********************lite***********************\n");
		lite = openfile("./lite.txt");
		if(my_read(lite, bufflite)> -1)
			printf("read success \n");
		else
			printf("bad\n");
		printf("\nthe bufflite\n%s\n",bufflite);
		close(lite);
		printf("\n********************gotos***********************\n");
		gotos = openfile("./gotos.txt");
		if(my_read(lite, buffgotos)> -1)
			printf("read success \n");
		else
			printf("bad\n");
		printf("\nthe buffgotos\n%s\n",bufflite);
		close(lite);
		printf("\n********************gramer***********************\n");
		gra = openfile("./grammar.txt");
		if(my_read(gra, buffgramm)> -1)
			printf("read success \n");
		else
			printf("bad\n");
		printf("\nthe bufflite\n%s\n",buffgramm);
		close(gra);
		printf("\n********************end***********************\n");
		grammer g;
		int result;
		initles_grammer(&g , bufflite ,buffgotos ,buffgramm , words);
		printf("\n----------------action----------------\n");
		printf_st(g.action);
		printf("\n----------------goto----------------\n");
		printf_st(g.gotos);
		printf("\n----------------production----------------\n");
		printf_gramexplist(g.production);
		printf("\n----------------sentence----------------\n");
		printf_wordlist(g.sentence);

		result = grammer_make(&g);
		putchar('\n');
		if(result == ok)
			putchar('Y');
		else
			putchar('N');
		printf("\n********************end***********************\n");
		return ok;

}

